﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Collections;

namespace BussinesLogic
{
    public class Usuario : BaseObject
    {
        public Usuario()
        {
        }

        
        #region Propiedades Publicas
        public int id { get; set; }

        public string Username
        { get; set; }

        public string Password
        { get; set; }

        public string Nombre1
        { get; set; }

        public string Nombre2
        { get; set; }

        public string Apellido1
        { get; set; }

        public string Apellido2
        { get; set; }

        public string Departamento
        { get; set; }

        public bool Administrador
        { get; set; }
        #endregion


        #region Funciones de Utilería
        public string toString()
        {
            return this.Username;
        }
        #endregion

        #region Funciones de Modelo
        public static Usuario logIn(string username, string password)
        {
            DataAccess.Factory.UsuarioFactoryDao tmpFac = new DataAccess.Factory.UsuarioFactoryDao();

            return tmpFac.getUserByUserNameAndPassword(username, password);
        }
        
        public static ArrayList all()
        {
            DataAccess.Factory.UsuarioFactoryDao tmpFac = new DataAccess.Factory.UsuarioFactoryDao();
            return tmpFac.getAllUsers();
        }

        public int Create()
        {
            try
            {
                DataAccess.Factory.UsuarioFactoryDao tmpFac = new DataAccess.Factory.UsuarioFactoryDao();
                this.id = tmpFac.createUser(this.xmlObjectDescription());
            }
            catch (Exception ex)
            {
                return -1;
            }
            return 0;
        }

        public string toXML()
        {
            return this.xmlObjectDescription();
        }
        
        #endregion
    }
}